/*
 * Copyright (c) 2013-2018 上海汇数数据. All rights reserved.
 * @(#) DateAttributeConverter.java 2018-08-10 09:03
 */

package cn.jh.common.core.support.jpa;

import org.jetbrains.annotations.Nullable;
import org.joda.time.DateTime;

import javax.persistence.AttributeConverter;
import java.util.Date;


/**
 * @author Fuchun
 * @since 1.0
 */
public class DateAttributeConverter implements AttributeConverter<DateTime, Date> {

    @Nullable
    @Override
    public Date convertToDatabaseColumn(DateTime dateTime) {
        return dateTime == null ? null : dateTime.toDate();
    }

    @Nullable
    @Override
    public DateTime convertToEntityAttribute(Date date) {
        return date == null ? null : new DateTime(date);
    }
}
